function ajax({ url, method = 'get', data = {}, timeout }) {
  let str = '';
  for (let i in data) {
    str += `${i}=${data[i]}&`
  }
  str = str.slice(0,-1)
  if (method === 'get') {
    url += '?' + str
  }
  // console.log(url)
  const xhr = new XMLHttpRequest();
  xhr.open(method, url, true);
  // console.log(str)
  if (method === 'get') {
    xhr.send()
  } else {
    // console.log(str);
    xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xhr.send(str)
  }
  return new Promise((resolve, reject) => {
    xhr.onload = function () {
      if (xhr.status === 200) {
        resolve(xhr.responseText)
      }else{
        reject(xhr.status)
      }
    }
  })
};
export {ajax};